﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmSocai_ct_theomuc.
	/// </summary>
	public class frmSocai_ct_theomuc : System.Windows.Forms.Form
	{
		//Khai bao gia tri mau cho form
		private int i_Red=255,i_Green=255,i_Blue=195;
		//End.
		//Khai bao bien su dung trong form.
		//private AccessData kt=new AccessData();
		private LibKetoan.AccessData a;
		private Print Print=new Print();
		private System.Data.DataRow r;
		private System.Data.DataTable dtDmtk,dtDmlk,dtDmmuc,dtHoatdong;
		private System.Data.DataSet dsData,dsSort;
		private string sql="",s_Report="";
		//
		private System.Windows.Forms.NumericUpDown numTuthang;
		private System.Windows.Forms.NumericUpDown numNam;
		private System.Windows.Forms.Button butIn;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Button butKetthuc;
		private System.Windows.Forms.NumericUpDown numDenthang;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox grpNen;
		private System.Windows.Forms.TextBox txtTentaikhoan;
		private System.Windows.Forms.TextBox txtTenloaikhoan;
		private System.Windows.Forms.TextBox txtTtk_Muc;
		private System.Windows.Forms.TextBox txtTenhd;
		private System.Windows.Forms.TextBox txtMahd;
		private System.Windows.Forms.TextBox txtStk_Muc;
		private System.Windows.Forms.TextBox txtLoaikhoan;
		private System.Windows.Forms.TextBox txtSotaikhoan;		
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label5;
		private LibList.List listMuc;
		private LibList.List listHoatdong;
		private LibList.List listLoaikhoan;
		private LibList.List listTaikhoan;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.Button butXem;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmSocai_ct_theomuc(LibKetoan.AccessData acc)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;
			
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
			try
			{
				a.Dispose();
				dtDmtk.Dispose();
				dtDmlk.Dispose();
				dsData.Dispose();
				dsSort.Dispose();
			}
			catch{};
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmSocai_ct_theomuc));
			this.numTuthang = new System.Windows.Forms.NumericUpDown();
			this.numNam = new System.Windows.Forms.NumericUpDown();
			this.butIn = new System.Windows.Forms.Button();
			this.label8 = new System.Windows.Forms.Label();
			this.butKetthuc = new System.Windows.Forms.Button();
			this.numDenthang = new System.Windows.Forms.NumericUpDown();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.grpNen = new System.Windows.Forms.GroupBox();
			this.txtTentaikhoan = new System.Windows.Forms.TextBox();
			this.txtTenloaikhoan = new System.Windows.Forms.TextBox();
			this.txtTtk_Muc = new System.Windows.Forms.TextBox();
			this.txtTenhd = new System.Windows.Forms.TextBox();
			this.txtMahd = new System.Windows.Forms.TextBox();
			this.txtStk_Muc = new System.Windows.Forms.TextBox();
			this.txtLoaikhoan = new System.Windows.Forms.TextBox();
			this.txtSotaikhoan = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label13 = new System.Windows.Forms.Label();
			this.butXem = new System.Windows.Forms.Button();
			this.listHoatdong = new LibList.List();
			this.listLoaikhoan = new LibList.List();
			this.listTaikhoan = new LibList.List();
			this.listMuc = new LibList.List();
			((System.ComponentModel.ISupportInitialize)(this.numTuthang)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.numDenthang)).BeginInit();
			this.SuspendLayout();
			// 
			// numTuthang
			// 
			this.numTuthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numTuthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.numTuthang.Location = new System.Drawing.Point(82, 16);
			this.numTuthang.Maximum = new System.Decimal(new int[] {
																	   12,
																	   0,
																	   0,
																	   0});
			this.numTuthang.Minimum = new System.Decimal(new int[] {
																	   1,
																	   0,
																	   0,
																	   0});
			this.numTuthang.Name = "numTuthang";
			this.numTuthang.Size = new System.Drawing.Size(37, 21);
			this.numTuthang.TabIndex = 3;
			this.numTuthang.Value = new System.Decimal(new int[] {
																	 1,
																	 0,
																	 0,
																	 0});
			this.numTuthang.Enter += new System.EventHandler(this.numTuthang_Enter);
			this.numTuthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numTuthang.Leave += new System.EventHandler(this.numTuthang_Leave);
			// 
			// numNam
			// 
			this.numNam.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numNam.ForeColor = System.Drawing.Color.DarkBlue;
			this.numNam.Location = new System.Drawing.Point(219, 16);
			this.numNam.Maximum = new System.Decimal(new int[] {
																   3004,
																   0,
																   0,
																   0});
			this.numNam.Minimum = new System.Decimal(new int[] {
																   2004,
																   0,
																   0,
																   0});
			this.numNam.Name = "numNam";
			this.numNam.Size = new System.Drawing.Size(48, 21);
			this.numNam.TabIndex = 9;
			this.numNam.Value = new System.Decimal(new int[] {
																 2004,
																 0,
																 0,
																 0});
			this.numNam.Enter += new System.EventHandler(this.numNam_Enter);
			this.numNam.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numNam.Leave += new System.EventHandler(this.numNam_Leave);
			// 
			// butIn
			// 
			this.butIn.BackColor = System.Drawing.SystemColors.Control;
			this.butIn.ForeColor = System.Drawing.Color.DarkBlue;
			this.butIn.Image = ((System.Drawing.Bitmap)(resources.GetObject("butIn.Image")));
			this.butIn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butIn.Location = new System.Drawing.Point(216, 192);
			this.butIn.Name = "butIn";
			this.butIn.Size = new System.Drawing.Size(60, 25);
			this.butIn.TabIndex = 52;
			this.butIn.Text = "     &In";
			this.butIn.Click += new System.EventHandler(this.butIn_Click);
			this.butIn.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// label8
			// 
			this.label8.BackColor = System.Drawing.SystemColors.Control;
			this.label8.ForeColor = System.Drawing.Color.DarkBlue;
			this.label8.Location = new System.Drawing.Point(20, 17);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(56, 23);
			this.label8.TabIndex = 2;
			this.label8.Text = "Từ tháng";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// butKetthuc
			// 
			this.butKetthuc.BackColor = System.Drawing.SystemColors.Control;
			this.butKetthuc.ForeColor = System.Drawing.Color.DarkBlue;
			this.butKetthuc.Image = ((System.Drawing.Bitmap)(resources.GetObject("butKetthuc.Image")));
			this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butKetthuc.Location = new System.Drawing.Point(278, 192);
			this.butKetthuc.Name = "butKetthuc";
			this.butKetthuc.Size = new System.Drawing.Size(70, 25);
			this.butKetthuc.TabIndex = 54;
			this.butKetthuc.Text = "&Kết thúc";
			this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
			this.butKetthuc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// numDenthang
			// 
			this.numDenthang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.numDenthang.ForeColor = System.Drawing.Color.DarkBlue;
			this.numDenthang.Location = new System.Drawing.Point(146, 16);
			this.numDenthang.Maximum = new System.Decimal(new int[] {
																		12,
																		0,
																		0,
																		0});
			this.numDenthang.Minimum = new System.Decimal(new int[] {
																		1,
																		0,
																		0,
																		0});
			this.numDenthang.Name = "numDenthang";
			this.numDenthang.Size = new System.Drawing.Size(37, 21);
			this.numDenthang.TabIndex = 7;
			this.numDenthang.Value = new System.Decimal(new int[] {
																	  1,
																	  0,
																	  0,
																	  0});
			this.numDenthang.Enter += new System.EventHandler(this.numDenthang_Enter);
			this.numDenthang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			this.numDenthang.Leave += new System.EventHandler(this.numDenthang_Leave);
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.SystemColors.Control;
			this.label2.ForeColor = System.Drawing.Color.DarkBlue;
			this.label2.Location = new System.Drawing.Point(112, 17);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(32, 23);
			this.label2.TabIndex = 6;
			this.label2.Text = "đến ";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.Control;
			this.label1.ForeColor = System.Drawing.Color.DarkBlue;
			this.label1.Location = new System.Drawing.Point(183, 17);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(34, 23);
			this.label1.TabIndex = 8;
			this.label1.Text = "năm";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// grpNen
			// 
			this.grpNen.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.grpNen.Location = new System.Drawing.Point(8, 40);
			this.grpNen.Name = "grpNen";
			this.grpNen.Size = new System.Drawing.Size(488, 128);
			this.grpNen.TabIndex = 99;
			this.grpNen.TabStop = false;
			// 
			// txtTentaikhoan
			// 
			this.txtTentaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTentaikhoan.CausesValidation = false;
			this.txtTentaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTentaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTentaikhoan.Location = new System.Drawing.Point(146, 59);
			this.txtTentaikhoan.Name = "txtTentaikhoan";
			this.txtTentaikhoan.ReadOnly = true;
			this.txtTentaikhoan.Size = new System.Drawing.Size(336, 21);
			this.txtTentaikhoan.TabIndex = 17;
			this.txtTentaikhoan.TabStop = false;
			this.txtTentaikhoan.Text = "";
			this.txtTentaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// txtTenloaikhoan
			// 
			this.txtTenloaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTenloaikhoan.CausesValidation = false;
			this.txtTenloaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTenloaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTenloaikhoan.Location = new System.Drawing.Point(146, 83);
			this.txtTenloaikhoan.Name = "txtTenloaikhoan";
			this.txtTenloaikhoan.ReadOnly = true;
			this.txtTenloaikhoan.Size = new System.Drawing.Size(339, 21);
			this.txtTenloaikhoan.TabIndex = 20;
			this.txtTenloaikhoan.TabStop = false;
			this.txtTenloaikhoan.Text = "";
			this.txtTenloaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// txtTtk_Muc
			// 
			this.txtTtk_Muc.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTtk_Muc.CausesValidation = false;
			this.txtTtk_Muc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTtk_Muc.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTtk_Muc.Location = new System.Drawing.Point(146, 107);
			this.txtTtk_Muc.Name = "txtTtk_Muc";
			this.txtTtk_Muc.ReadOnly = true;
			this.txtTtk_Muc.Size = new System.Drawing.Size(339, 21);
			this.txtTtk_Muc.TabIndex = 23;
			this.txtTtk_Muc.TabStop = false;
			this.txtTtk_Muc.Text = "";
			this.txtTtk_Muc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// txtTenhd
			// 
			this.txtTenhd.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtTenhd.CausesValidation = false;
			this.txtTenhd.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtTenhd.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtTenhd.Location = new System.Drawing.Point(146, 131);
			this.txtTenhd.Name = "txtTenhd";
			this.txtTenhd.ReadOnly = true;
			this.txtTenhd.Size = new System.Drawing.Size(339, 21);
			this.txtTenhd.TabIndex = 26;
			this.txtTenhd.TabStop = false;
			this.txtTenhd.Text = "";
			this.txtTenhd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.event_KeyDown);
			// 
			// txtMahd
			// 
			this.txtMahd.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtMahd.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.txtMahd.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtMahd.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtMahd.Location = new System.Drawing.Point(82, 131);
			this.txtMahd.Name = "txtMahd";
			this.txtMahd.Size = new System.Drawing.Size(63, 21);
			this.txtMahd.TabIndex = 25;
			this.txtMahd.Text = "";
			this.txtMahd.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtMahd_KeyDown);
			this.txtMahd.Validated += new System.EventHandler(this.txtMahd_Validated);
			this.txtMahd.TextChanged += new System.EventHandler(this.txtMahd_TextChanged);
			this.txtMahd.DoubleClick += new System.EventHandler(this.txtMahd_DoubleClick);
			this.txtMahd.Leave += new System.EventHandler(this.txtMahd_Leave);
			this.txtMahd.Enter += new System.EventHandler(this.txtMahd_Enter);
			// 
			// txtStk_Muc
			// 
			this.txtStk_Muc.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtStk_Muc.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.txtStk_Muc.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtStk_Muc.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtStk_Muc.Location = new System.Drawing.Point(82, 107);
			this.txtStk_Muc.Name = "txtStk_Muc";
			this.txtStk_Muc.Size = new System.Drawing.Size(63, 21);
			this.txtStk_Muc.TabIndex = 22;
			this.txtStk_Muc.Text = "";
			this.txtStk_Muc.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtStk_Muc_KeyDown);
			this.txtStk_Muc.Validated += new System.EventHandler(this.txtStk_Muc_Validated);
			this.txtStk_Muc.TextChanged += new System.EventHandler(this.txtStk_Muc_TextChanged);
			this.txtStk_Muc.DoubleClick += new System.EventHandler(this.txtStk_Muc_DoubleClick);
			this.txtStk_Muc.Leave += new System.EventHandler(this.txtStk_Muc_Leave);
			this.txtStk_Muc.Enter += new System.EventHandler(this.txtStk_Muc_Enter);
			// 
			// txtLoaikhoan
			// 
			this.txtLoaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtLoaikhoan.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.txtLoaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtLoaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtLoaikhoan.Location = new System.Drawing.Point(82, 83);
			this.txtLoaikhoan.Name = "txtLoaikhoan";
			this.txtLoaikhoan.Size = new System.Drawing.Size(63, 21);
			this.txtLoaikhoan.TabIndex = 19;
			this.txtLoaikhoan.Text = "";
			this.txtLoaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLoaikhoan_KeyDown);
			this.txtLoaikhoan.Validated += new System.EventHandler(this.txtLoaikhoan_Validated);
			this.txtLoaikhoan.TextChanged += new System.EventHandler(this.txtLoaikhoan_TextChanged);
			this.txtLoaikhoan.DoubleClick += new System.EventHandler(this.txtLoaikhoan_DoubleClick);
			this.txtLoaikhoan.Leave += new System.EventHandler(this.numLoaikhoan_Leave);
			this.txtLoaikhoan.Enter += new System.EventHandler(this.txtLoaikhoan_Enter);
			// 
			// txtSotaikhoan
			// 
			this.txtSotaikhoan.BackColor = System.Drawing.SystemColors.HighlightText;
			this.txtSotaikhoan.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
			this.txtSotaikhoan.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtSotaikhoan.ForeColor = System.Drawing.Color.DarkBlue;
			this.txtSotaikhoan.Location = new System.Drawing.Point(82, 59);
			this.txtSotaikhoan.Name = "txtSotaikhoan";
			this.txtSotaikhoan.Size = new System.Drawing.Size(63, 21);
			this.txtSotaikhoan.TabIndex = 16;
			this.txtSotaikhoan.Text = "";
			this.txtSotaikhoan.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtSotaikhoan_KeyDown);
			this.txtSotaikhoan.Validated += new System.EventHandler(this.txtSotaikhoan_Validated);
			this.txtSotaikhoan.TextChanged += new System.EventHandler(this.txtSotaikhoan_TextChanged);
			this.txtSotaikhoan.DoubleClick += new System.EventHandler(this.txtSotaikhoan_DoubleClick);
			this.txtSotaikhoan.Leave += new System.EventHandler(this.numSotaikhoan_Leave);
			this.txtSotaikhoan.Enter += new System.EventHandler(this.txtSotaikhoan_Enter);
			// 
			// label5
			// 
			this.label5.BackColor = System.Drawing.SystemColors.Control;
			this.label5.ForeColor = System.Drawing.Color.DarkBlue;
			this.label5.Location = new System.Drawing.Point(11, 132);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(72, 23);
			this.label5.TabIndex = 24;
			this.label5.Text = "Hoạt động :";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.SystemColors.Control;
			this.label3.ForeColor = System.Drawing.Color.DarkBlue;
			this.label3.Location = new System.Drawing.Point(10, 108);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 23);
			this.label3.TabIndex = 21;
			this.label3.Text = "Mục :";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.SystemColors.Control;
			this.label4.ForeColor = System.Drawing.Color.DarkBlue;
			this.label4.Location = new System.Drawing.Point(10, 84);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(72, 23);
			this.label4.TabIndex = 18;
			this.label4.Text = "Loại khoản :";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label13
			// 
			this.label13.BackColor = System.Drawing.SystemColors.Control;
			this.label13.ForeColor = System.Drawing.Color.DarkBlue;
			this.label13.Location = new System.Drawing.Point(10, 59);
			this.label13.Name = "label13";
			this.label13.Size = new System.Drawing.Size(72, 23);
			this.label13.TabIndex = 15;
			this.label13.Text = "Tài khoản :";
			this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// butXem
			// 
			this.butXem.BackColor = System.Drawing.SystemColors.Control;
			this.butXem.ForeColor = System.Drawing.SystemColors.WindowText;
			this.butXem.Image = ((System.Drawing.Bitmap)(resources.GetObject("butXem.Image")));
			this.butXem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
			this.butXem.Location = new System.Drawing.Point(154, 192);
			this.butXem.Name = "butXem";
			this.butXem.Size = new System.Drawing.Size(60, 25);
			this.butXem.TabIndex = 51;
			this.butXem.Text = "     &Xem";
			this.butXem.Click += new System.EventHandler(this.butXem_Click);
			// 
			// listHoatdong
			// 
			this.listHoatdong.BackColor = System.Drawing.SystemColors.Info;
			this.listHoatdong.ColumnCount = 0;
			this.listHoatdong.Location = new System.Drawing.Point(424, 368);
			this.listHoatdong.MatchBufferTimeOut = 1000;
			this.listHoatdong.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listHoatdong.Name = "listHoatdong";
			this.listHoatdong.Size = new System.Drawing.Size(75, 17);
			this.listHoatdong.TabIndex = 106;
			this.listHoatdong.TextIndex = -1;
			this.listHoatdong.TextMember = null;
			this.listHoatdong.ValueIndex = -1;
			this.listHoatdong.Visible = false;
			// 
			// listLoaikhoan
			// 
			this.listLoaikhoan.BackColor = System.Drawing.SystemColors.Info;
			this.listLoaikhoan.ColumnCount = 0;
			this.listLoaikhoan.Location = new System.Drawing.Point(424, 368);
			this.listLoaikhoan.MatchBufferTimeOut = 1000;
			this.listLoaikhoan.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listLoaikhoan.Name = "listLoaikhoan";
			this.listLoaikhoan.Size = new System.Drawing.Size(75, 17);
			this.listLoaikhoan.TabIndex = 106;
			this.listLoaikhoan.TextIndex = -1;
			this.listLoaikhoan.TextMember = null;
			this.listLoaikhoan.ValueIndex = -1;
			this.listLoaikhoan.Visible = false;
			// 
			// listTaikhoan
			// 
			this.listTaikhoan.BackColor = System.Drawing.SystemColors.Info;
			this.listTaikhoan.ColumnCount = 0;
			this.listTaikhoan.Location = new System.Drawing.Point(424, 368);
			this.listTaikhoan.MatchBufferTimeOut = 1000;
			this.listTaikhoan.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listTaikhoan.Name = "listTaikhoan";
			this.listTaikhoan.Size = new System.Drawing.Size(75, 17);
			this.listTaikhoan.TabIndex = 106;
			this.listTaikhoan.TextIndex = -1;
			this.listTaikhoan.TextMember = null;
			this.listTaikhoan.ValueIndex = -1;
			this.listTaikhoan.Visible = false;
			// 
			// listMuc
			// 
			this.listMuc.BackColor = System.Drawing.SystemColors.Info;
			this.listMuc.ColumnCount = 0;
			this.listMuc.Location = new System.Drawing.Point(424, 368);
			this.listMuc.MatchBufferTimeOut = 1000;
			this.listMuc.MatchEntryStyle = AsYetUnnamed.MatchEntryStyle.FirstLetterInsensitive;
			this.listMuc.Name = "listMuc";
			this.listMuc.Size = new System.Drawing.Size(75, 17);
			this.listMuc.TabIndex = 106;
			this.listMuc.TextIndex = -1;
			this.listMuc.TextMember = null;
			this.listMuc.ValueIndex = -1;
			this.listMuc.Visible = false;
			// 
			// frmSocai_ct_theomuc
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(502, 235);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.txtTentaikhoan,
																		  this.txtTenloaikhoan,
																		  this.txtTtk_Muc,
																		  this.txtTenhd,
																		  this.txtMahd,
																		  this.txtStk_Muc,
																		  this.txtLoaikhoan,
																		  this.txtSotaikhoan,
																		  this.label5,
																		  this.label3,
																		  this.label4,
																		  this.label13,
																		  this.numDenthang,
																		  this.numTuthang,
																		  this.numNam,
																		  this.label1,
																		  this.label2,
																		  this.label8,
																		  this.butKetthuc,
																		  this.butXem,
																		  this.butIn,
																		  this.listHoatdong,
																		  this.listLoaikhoan,
																		  this.listMuc,
																		  this.listTaikhoan,
																		  this.grpNen});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmSocai_ct_theomuc";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Sổ cái (chi tiết theo mục)";
			this.TopMost = true;
			this.Load += new System.EventHandler(this.frmSocai_ct_theomuc_Load);
			((System.ComponentModel.ISupportInitialize)(this.numTuthang)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numNam)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.numDenthang)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmSocai_ct_theomuc_Load(object sender, System.EventArgs e)
		{
			//Gan gia tri khoi tao cho cac o thang nam
			numTuthang.Focus();
			numTuthang.Value=DateTime.Now.Month;
			numDenthang.Value=DateTime.Now.Month;
			numNam.Value=DateTime.Now.Year;
			numNam.Value=DateTime.Now.Year;
			//

			listTaikhoan.DisplayMember="TTK";
			listTaikhoan.TextMember="STK";
			listTaikhoan.ValueMember="TTK";

			listLoaikhoan.DisplayMember="TLK";
			listLoaikhoan.TextMember="LK";
			listLoaikhoan.ValueMember="TLK";

			listMuc.DisplayMember="TTK";
			listMuc.TextMember="STK";
			listMuc.ValueMember="TTK";

			listHoatdong.DisplayMember="TEN";
			listHoatdong.TextMember="MA";
			listHoatdong.ValueMember="TEN";

			load_dm();
			txtSotaikhoan.Focus();

		}

		private void load_dm()
		{
			sql="select stk,ttk,id,sp,hethong from a_dmtk where mlns=1 order by stk";
			dtDmtk=a.get_data(sql).Tables[0];
			listTaikhoan.DataSource=dtDmtk;
			
			sql="select lk,tlk,id from a_dmlk order by lk";
			dtDmlk=a.get_data(sql).Tables[0];
			listLoaikhoan.DataSource=dtDmlk;

			//sql="select trim(stk) stk,trim(ttk) ttk,id,p,n,tn,cc,nhmuc from a_dmch where sudung=1 and length(trim(stk))=3 order by trim(stk)";

			//dtDmmuc=a.get_data(sql).Tables[0];
			dtDmmuc=a.get_DMMuc().Tables[0];
			listMuc.DataSource=dtDmmuc;

			sql="select ma,ten,id,stt from a_hoatdong where sudung=1 order by stt";
			dtHoatdong=a.get_data(sql).Tables[0];
			listHoatdong.DataSource=dtHoatdong;
		}

		private void hide_List()
		{
			if(!listTaikhoan.Focused) listTaikhoan.Hide();
			if(!listLoaikhoan.Focused) listLoaikhoan.Hide();
			if(!listMuc.Focused) listMuc.Hide();
			if(!listHoatdong.Focused) listHoatdong.Hide();
		}
		

		private void event_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab || e.KeyValue==13)
			{
				SendKeys.Send("{Tab}");
			}
		}
		
		private void numTuthang_Enter(object sender, System.EventArgs e)
		{
			this.numTuthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numDenthang_Enter(object sender, System.EventArgs e)
		{
			this.numDenthang.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numNam_Enter(object sender, System.EventArgs e)
		{
			this.numNam.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void txtSotaikhoan_Enter(object sender, System.EventArgs e)
		{
			this.txtSotaikhoan.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void txtLoaikhoan_Enter(object sender, System.EventArgs e)
		{
			this.txtLoaikhoan.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void txtStk_Muc_Enter(object sender, System.EventArgs e)
		{
			this.txtStk_Muc.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void txtMahd_Enter(object sender, System.EventArgs e)
		{
			this.txtMahd.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(i_Red)), ((System.Byte)(i_Green)), ((System.Byte)(i_Blue)));
		}

		private void numTuthang_Leave(object sender, System.EventArgs e)
		{
			this.numTuthang.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numDenthang_Leave(object sender, System.EventArgs e)
		{
			this.numDenthang.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numNam_Leave(object sender, System.EventArgs e)
		{
			this.numNam.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numSotaikhoan_Leave(object sender, System.EventArgs e)
		{
			this.txtSotaikhoan.BackColor = System.Drawing.SystemColors.Window;
		}

		private void numLoaikhoan_Leave(object sender, System.EventArgs e)
		{
			this.txtLoaikhoan.BackColor = System.Drawing.SystemColors.Window;
		}

		private void txtStk_Muc_Leave(object sender, System.EventArgs e)
		{
			this.txtStk_Muc.BackColor = System.Drawing.SystemColors.Window;
		}

		private void txtMahd_Leave(object sender, System.EventArgs e)
		{
			this.txtMahd.BackColor = System.Drawing.SystemColors.Window;
		}


		private void Filter_List(string s_Dkloc,int i_Loai)
		{
			try
			{
				switch (i_Loai)
				{
					case 1:
					{
						CurrencyManager cm= (CurrencyManager)BindingContext[listTaikhoan.DataSource];
						System.Data.DataView dv=(System.Data.DataView)cm.List;
						dv.RowFilter="stk like '%"+s_Dkloc.Trim()+"%'";
						break;
					}
					case 2:
					{
						CurrencyManager cm= (CurrencyManager)BindingContext[listLoaikhoan.DataSource];
						System.Data.DataView dv=(System.Data.DataView)cm.List;
						dv.RowFilter="lk like '%"+s_Dkloc.Trim()+"%'";
						break;
					}
					case 3:
					{
						CurrencyManager cm= (CurrencyManager)BindingContext[listMuc.DataSource];
						System.Data.DataView dv=(System.Data.DataView)cm.List;
						dv.RowFilter="stk like '%"+s_Dkloc.Trim()+"%'";
						break;
					}
					case 4:
					{
						CurrencyManager cm= (CurrencyManager)BindingContext[listHoatdong.DataSource];
						System.Data.DataView dv=(System.Data.DataView)cm.List;
						dv.RowFilter="ma like '%"+s_Dkloc.Trim()+"%'";
						break;
					}
					default:
						break;
				}

			}
			catch{}
		}

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void txtSotaikhoan_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listTaikhoan.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listTaikhoan.Visible) listTaikhoan.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void txtSotaikhoan_DoubleClick(object sender, System.EventArgs e)
		{
			listTaikhoan.Focus();
			Filter_List(txtSotaikhoan.Text,1);
			listTaikhoan.BrowseToDmtk(txtSotaikhoan,txtTentaikhoan,txtLoaikhoan,txtSotaikhoan.Location.X,txtSotaikhoan.Location.Y + txtSotaikhoan.Height-2,txtSotaikhoan.Width+0+txtTentaikhoan.Width,txtSotaikhoan.Height+5,100);			
		}

		private void txtSotaikhoan_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtSotaikhoan)
			{
				Filter_List(txtSotaikhoan.Text,1);
				listTaikhoan.BrowseToDmtk(txtSotaikhoan,txtTentaikhoan,txtLoaikhoan,txtSotaikhoan.Location.X,txtSotaikhoan.Location.Y + txtSotaikhoan.Height-2,txtSotaikhoan.Width+0+txtTentaikhoan.Width,txtSotaikhoan.Height+5,100);
			}	
		}

		private void txtSotaikhoan_Validated(object sender, System.EventArgs e)
		{
			txtTentaikhoan.Text="";
			if (txtSotaikhoan.Text!="")
			{
				r=a.getrowbyid(dtDmtk,"stk='"+txtSotaikhoan.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTentaikhoan.Text=r["ttk"].ToString();
				}
			}
			hide_List();
		}

		private void txtLoaikhoan_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listLoaikhoan.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listLoaikhoan.Visible) listLoaikhoan.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void txtLoaikhoan_DoubleClick(object sender, System.EventArgs e)
		{
			listLoaikhoan.Focus();
			Filter_List(txtLoaikhoan.Text,2);
			listLoaikhoan.BrowseToDmtk(txtLoaikhoan,txtTenloaikhoan,butXem,txtLoaikhoan.Location.X,txtLoaikhoan.Location.Y + txtLoaikhoan.Height-2,txtLoaikhoan.Width+0+txtTenloaikhoan.Width,txtLoaikhoan.Height+5,100);
		}

		private void txtLoaikhoan_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtLoaikhoan)
			{
				Filter_List(txtLoaikhoan.Text,2);
				listLoaikhoan.BrowseToDmtk(txtLoaikhoan,txtTenloaikhoan,txtStk_Muc,txtLoaikhoan.Location.X,txtLoaikhoan.Location.Y + txtLoaikhoan.Height-2,txtLoaikhoan.Width+0+txtTenloaikhoan.Width,txtLoaikhoan.Height+5,100);
			}	
		}

		private void txtLoaikhoan_Validated(object sender, System.EventArgs e)
		{
			txtTenloaikhoan.Text="";
			if (txtLoaikhoan.Text!="")
			{
				r=a.getrowbyid(dtDmlk,"lk='"+txtLoaikhoan.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTenloaikhoan.Text=r["tlk"].ToString();
				}
			}
			hide_List();
		}

		private void txtStk_Muc_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listMuc.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listMuc.Visible) listMuc.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void txtStk_Muc_DoubleClick(object sender, System.EventArgs e)
		{
			listMuc.Focus();
			Filter_List(txtStk_Muc.Text,3);
			listMuc.BrowseToDmtk(txtStk_Muc,txtTtk_Muc,txtMahd,txtStk_Muc.Location.X,txtStk_Muc.Location.Y + txtStk_Muc.Height-2,txtStk_Muc.Width+0+txtTtk_Muc.Width,txtStk_Muc.Height+5,100);
		}

		private void txtStk_Muc_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtStk_Muc)
			{
				Filter_List(txtStk_Muc.Text,3);
				listMuc.BrowseToDmtk(txtStk_Muc,txtTtk_Muc,txtMahd,txtStk_Muc.Location.X,txtStk_Muc.Location.Y + txtStk_Muc.Height-2,txtStk_Muc.Width+0+txtTtk_Muc.Width,txtStk_Muc.Height+5,100);
			}	
		}

		private void txtStk_Muc_Validated(object sender, System.EventArgs e)
		{
			txtTtk_Muc.Text="";
			if (txtStk_Muc.Text!="")
			{
				r=a.getrowbyid(dtDmmuc,"stk='"+txtStk_Muc.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTtk_Muc.Text=r["ttk"].ToString();
				}
			}
			hide_List();
		}

		private void txtMahd_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Down || e.KeyCode==Keys.Up) listHoatdong.Focus();
			else if (e.KeyCode==Keys.Enter || e.KeyCode==Keys.Tab)
			{
				if (listHoatdong.Visible) listHoatdong.Focus();
				else SendKeys.Send("{Tab}");
			}
		}

		private void txtMahd_DoubleClick(object sender, System.EventArgs e)
		{
			listHoatdong.Focus();
			Filter_List(txtMahd.Text,4);
			listHoatdong.BrowseToDmtk(txtMahd,txtTenhd,butXem,txtMahd.Location.X,txtMahd.Location.Y + txtMahd.Height-2,txtMahd.Width+0+txtTenhd.Width,txtMahd.Height+5,100);
		}

		private void txtMahd_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtMahd)
			{
				Filter_List(txtMahd.Text,4);
				listHoatdong.BrowseToDmtk(txtMahd,txtTenhd,butXem,txtMahd.Location.X,txtMahd.Location.Y + txtMahd.Height-2,txtMahd.Width+0+txtTenhd.Width,txtMahd.Height+5,100);
			}	
		}

		private void txtMahd_Validated(object sender, System.EventArgs e)
		{
			txtTenhd.Text="";
			if (txtMahd.Text!="")
			{
				r=a.getrowbyid(dtHoatdong,"ma='"+txtMahd.Text.Trim()+"'");
				if (r!=null) 
				{
					txtTenhd.Text=r["ten"].ToString();
				}
			}
			hide_List();
		}

		private void Display(int loai)
		//Loai display: 1 - xuat ra man hinh; 2 - xuat ra may in. 
		{
			if (numDenthang.Value<numTuthang.Value) numDenthang.Value=numTuthang.Value;
			decimal sumAll=0;bool flag_dsnull=false;

			dsData=new System.Data.DataSet();
			string s_sql_Sodu="";
			int yy=int.Parse(numNam.Value.ToString()), mm1=int.Parse(numTuthang.Value.ToString());
			int mm2=int.Parse(numDenthang.Value.ToString());
			string s_yy=yy.ToString().PadLeft(4,'0').Substring(2,2);
			string s_Tungay=numTuthang.Value.ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString().PadLeft(4,'0');
			string s_Denngay=numDenthang.Value.ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString().PadLeft(4,'0');
			string s_IDtk="",s_IDlk="",s_mmyyyy="",s_IDmuc="",s_IDhoatdong="",s_Nguonns="";

			if (txtSotaikhoan.Text=="")
			{
				MessageBox.Show("Vui lòng nhập số tài khoản!","Chú ý!");
				txtSotaikhoan.Focus();
				return;
			}

			string s_Thangnam=a.kt_Tinhsodu(mm1.ToString(),s_yy);
			if (s_Thangnam!="")
			{
				MessageBox.Show("Các tháng "+s_Thangnam.Substring(0,s_Thangnam.Length-1)+" chưa tính số dư!","Chú ý!");
				return;
			}

			try
			{
				int i_LengthTK=txtSotaikhoan.Text.ToString().Trim().Length;
				sql="select id from a_dmtk where substr(stk,1,"+i_LengthTK+")='"+txtSotaikhoan.Text.Trim()+"' order by id";
				foreach(System.Data.DataRow dr in a.get_data(sql).Tables[0].Rows)
				{ 
					s_IDtk+=dr["id"].ToString()+",";
				}
				if (s_IDtk.Substring(s_IDtk.Length-1,1)==",") s_IDtk=s_IDtk.Substring(0,s_IDtk.Length-1);
				if (txtLoaikhoan.Text!="") s_IDlk=a.getrowbyid(dtDmlk,"lk='"+txtLoaikhoan.Text.Trim()+"'")["id"].ToString().Trim();
				
				if (txtStk_Muc.Text!="")
				{
					sql=" select id from a_dmch where mtm like '"+txtStk_Muc.Text.Trim()+"%' order by id";
					//sql="select id from a_dmch where substr(trim(mtm),6,trim(length(mtm)))='"+txtStk_Muc.Text.Trim()+"' order by id";
					foreach(System.Data.DataRow dr in a.get_data(sql).Tables[0].Rows)
					{ 
						s_IDmuc+=dr["id"].ToString()+",";
					}
				}
				if (s_IDmuc.Substring(s_IDmuc.Length-1,1)==",") s_IDmuc=s_IDmuc.Substring(0,s_IDmuc.Length-1);
			}
			catch{}	;
			try
			{
				if ((txtSotaikhoan.Text.Trim().IndexOf(".")>0) && (txtMahd.Text!=""))
				{
					s_IDhoatdong=a.getrowbyid(dtHoatdong,"ma='"+txtMahd.Text.Trim()+"'")["id"].ToString().Trim();
					string s_Manguon=txtSotaikhoan.Text.Trim().Split('.')[1].ToString();
					sql="select mang,ten,id from a_dmng where sudung=1 and mang='"+s_Manguon+"' and loaikp='"+s_IDhoatdong+"' order by mang";
					s_Nguonns=a.get_datarow(sql)["ten"].ToString();
				}
			}
			catch{}	;

			sql=  "select distinct to_char(ct.ngayg,'mm/yyyy') thangg,";
			if (s_IDmuc!="")
			{
				sql+=" case when (ctct.tknoa in("+s_IDtk+") and ctct.mtmno in("+s_IDmuc+")) then substr(trim(dmchno.mtm),1,4) ";
				sql+="  when (ctct.tkcoa in("+s_IDtk+") and ctct.mtmco in("+s_IDmuc+")) then substr(trim(dmchco.mtm),1,4) end nhommuc,";
			}
			else 
			{
				sql+=" case when ctct.tknoa in("+s_IDtk+") then substr(trim(dmchno.stk),1,4) ";
				sql+=" when ctct.tkcoa in("+s_IDtk+") then substr(trim(dmchco.stk),1,4) end nhommuc,";
			}
			sql+=" ct.ngaygs ngaygs,ct.soctg,ct.ngayg ngayg,";
			sql+=" nvl(ctct.noidung,ct.noidung) diengiai,(case when ctct.tknoa in("+s_IDtk+") then dmtkco.stk else (case when";
			sql+=" ctct.tkcoa in("+s_IDtk+") then dmtkno.stk else '' end) end) tkdoiung,";
			if (s_IDmuc!="")
			{
				sql+=" case when (ctct.tknoa in("+s_IDtk+") and ctct.mtmno in("+s_IDmuc+")) then substr(trim(dmchno.mtm),0,trim(length(dmchno.mtm))) ";
				sql+="  when (ctct.tkcoa in("+s_IDtk+") and ctct.mtmco in("+s_IDmuc+")) then substr(trim(dmchco.mtm),0,trim(length(dmchco.mtm))) end muc,";
			}
			else 
			{
				sql+=" case when ctct.tknoa in("+s_IDtk+") then substr(trim(dmchno.mtm),6,trim(length(dmchno.mtm))) ";
				sql+=" when ctct.tkcoa in("+s_IDtk+") then substr(trim(dmchco.mtm),6,trim(length(dmchco.mtm))) end muc,";
			}
			sql+=" (case when ctct.tknoa in("+s_IDtk+") then ctct.stien else 0 end) sotienno,";
			sql+=" (case when ctct.tkcoa in("+s_IDtk+") then ctct.stien else 0 end) sotienco,";
			sql+=" 0 tondauno,0 tondauco,0 tondaumucno,0 tondaumucco,0 fsnoquy,0 fscoquy,0 fsnonam,0 fsconam,' ' ghichu,";
			sql+=" (case when ctct.tknoa in("+s_IDtk+") then 1 else 2 end) loaictu,to_number(to_char(ct.ngayg,'yyyymm')||'2') sapxep";
			sql+=" from a_ct"+s_yy+" ct,a_ctct"+s_yy+" ctct,a_dmlk lk,a_dmtk dmtkno,a_dmtk dmtkco,a_dmch dmchno,a_dmch dmchco"; 
			sql+=" where ct.id=ctct.idct and ctct.lk=lk.id(+) and ctct.tonghop=1";
			sql+=" and ctct.tknoa=dmtkno.id and ctct.tkcoa=dmtkco.id";
			if (s_IDmuc!="") sql+=" and (ctct.mtmno in("+s_IDmuc+") or ctct.mtmco in("+s_IDmuc+"))";
			sql+=" and ctct.mtmno=dmchno.id(+) and ctct.mtmco=dmchco.id(+)";
			sql+=" and to_date(to_char(ct.ngayg,'mm/yyyy'),'mm/yyyy') between to_date('"+s_Tungay+"','mm/yyyy') and to_date('"+s_Denngay+"','mm/yyyy')";
			if (s_IDlk!="") sql+=" and lk.id='"+s_IDlk+"'";
			sql+=" and (ctct.tknoa in("+s_IDtk+") or ctct.tkcoa in("+s_IDtk+"))";
			sql+=" order by to_char(ct.ngayg,'mm/yyyy'),ct.ngayg";

			s_sql_Sodu=  "select distinct '"+s_Tungay+"' thangg,nvl(substr(trim(dmch.stk),1,4),'000') nhommuc,";
			s_sql_Sodu+=" to_date('01/"+s_Tungay+"','dd/mm/yyyy') ngaygs,' ' soctg,to_date('01/"+s_Tungay+"','dd/mm/yyyy') ngayg,";
			s_sql_Sodu+=" 'So du dau ky theo muc' diengiai,' ' tkdoiung,'' muc,0 sotienno,0 sotienco,0 tondauno,";
			s_sql_Sodu+=" 0 tondauco,sum(sd.sdno"+numTuthang.Value.ToString().PadLeft(2,'0')+") tondaumucno,";
			s_sql_Sodu+=" sum(sd.sdco"+numTuthang.Value.ToString().PadLeft(2,'0')+") tondaumucco,0 fsnoquy,0 fscoquy,";
			s_sql_Sodu+=" 0 fsnonam,0 fsconam,' ' ghichu,3 loaictu,to_number('"+numNam.Value.ToString()+numTuthang.Value.ToString().PadLeft(2,'0')+"'||'3') sapxep";
			s_sql_Sodu+=" from a_sd"+s_yy+" sd,a_dmch dmch where sd.mtmuc=dmch.id(+) and sd.stka in("+s_IDtk+")";
			if (s_IDlk!="") s_sql_Sodu+=" and sd.lk='"+s_IDlk+"'";
			if (s_IDmuc!="") s_sql_Sodu+=" and sd.mtmuc in("+s_IDmuc+")";
			s_sql_Sodu+=" group by '"+s_Tungay+"',nvl(substr(trim(dmch.stk),1,4),'000'),to_date('01/"+s_Tungay+"','dd/mm/yyyy'),";
			s_sql_Sodu+=" ' ',to_date('01/"+s_Tungay+"','dd/mm/yyyy'),'So du dau ky theo muc',' ','',0,0,0,0,0,0,0,0,' ',";
			s_sql_Sodu+=" 3,to_number('"+numNam.Value.ToString()+numTuthang.Value.ToString().PadLeft(2,'0')+"'||'3')";

			try
			{
				dsData=a.get_data(sql).Copy();
				if ((dsData==null || dsData.Tables[0].Rows.Count<=0)) 
					dsData=a.get_data(s_sql_Sodu).Copy();
				else 
					dsData.Merge(a.get_data(s_sql_Sodu).Copy());
				
				if ((dsData==null || dsData.Tables[0].Rows.Count<=0)) flag_dsnull=true;
			}
			catch
			{
				flag_dsnull=true;
			}

			try
			{
				dsSort=dsData.Copy();
				decimal d_Daukyno=0,d_Daukyco=0,d_FSquyno=0,d_FSquyco=0,d_FSnamno=0,d_FSnamco=0;
				//Them dong load so du dau ky.
				for (int j=mm1;j<=mm2;j++)
				{
					try
					{ 
						System.Data.DataRow drSodu = dsSort.Tables[0].NewRow();
						drSodu["thangg"]=j.ToString().PadLeft(2,'0')+"/"+yy.ToString().PadLeft(4,'0');
						drSodu["nhommuc"]="";
						drSodu["ngaygs"]=DateTime.Parse(j.ToString().PadLeft(2,'0')+"/01/"+yy.ToString());
						drSodu["soctg"]="";
						drSodu["ngayg"]=DateTime.Parse(j.ToString().PadLeft(2,'0')+"/01/"+yy.ToString());
						drSodu["diengiai"]="Số dư đầu tháng";
						drSodu["tkdoiung"]="";

						//Tham so cuoi: 1-lay so du no hoac phat sinh no, 2-lay so du co hoac phat sinh co.
						drSodu["sotienno"]=0;
						drSodu["sotienco"]=0;
						
						drSodu["ghichu"]="";
						drSodu["loaictu"]=0;
						drSodu["sapxep"]=int.Parse(yy.ToString()+j.ToString().PadLeft(2,'0')+"1");

						//Set lai phat sinh quy khi qua quy moi.
						if (((j-1) % 3)==0)
						{
							d_FSquyno=0;
							d_FSquyco=0;
						}
						//

						if (j==mm1)
						{
							d_Daukyno=a.get_Sodudauky(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,1);
							d_Daukyco=a.get_Sodudauky(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,2);

							d_FSquyno=a.get_FSluykequy(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,1);
							d_FSquyco=a.get_FSluykequy(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,2);

							d_FSnamno=a.get_FSluykenam(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,1);
							d_FSnamco=a.get_FSluykenam(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,2);
							sumAll+=d_Daukyno+d_Daukyco+d_FSquyno+d_FSquyco+d_FSnamno+d_FSnamco;
						}
						else
						{
							s_mmyyyy=(j-1).ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString().PadLeft(4,'0');
							decimal d_Luyke_ds_no=a.get_FSluyke_ds("thangg='"+s_mmyyyy+"'",dsData,"sotienno","sotienco",1);
							decimal d_Luyke_ds_co=a.get_FSluyke_ds("thangg='"+s_mmyyyy+"'",dsData,"sotienno","sotienco",2);

							d_Daukyno=(d_Daukyno+d_Luyke_ds_no) - Math.Min((d_Daukyno+d_Luyke_ds_no),(d_Daukyco+d_Luyke_ds_co));
							d_Daukyco=(d_Daukyco+d_Luyke_ds_co) - Math.Min((d_Daukyno+d_Luyke_ds_no),(d_Daukyco+d_Luyke_ds_co));

							d_FSquyno+=d_Luyke_ds_no;
							d_FSquyco+=d_Luyke_ds_co;

							d_FSnamno+=d_Luyke_ds_no;
							d_FSnamco+=d_Luyke_ds_co;
							sumAll+=d_Daukyno+d_Daukyco+d_FSquyno+d_FSquyco+d_FSnamno+d_FSnamco;
						}

						drSodu["tondauno"]=d_Daukyno;
						drSodu["tondauco"]=d_Daukyco;

						drSodu["tondaumucno"]=0;
						drSodu["tondaumucco"]=0;
						
						drSodu["fsnoquy"]=d_FSquyno;
						drSodu["fscoquy"]=d_FSquyco;

						drSodu["fsnonam"]=d_FSnamno;
						drSodu["fsconam"]=d_FSnamco;

						dsSort.Tables[0].Rows.Add(drSodu);
						dsSort.AcceptChanges();
					}
					catch{}	;
					
					if (j<mm2)
					{
						string s_Duyetmuc="";
						int i_Somuc=0;
						string s_Thangg=j.ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString();
						//Them dong load so du dau ky theo muc.
						foreach (System.Data.DataRow drMuc in dsData.Tables[0].Select("thangg='"+s_Thangg+"'"))
						{
							try
							{ 
								string s_mtm=drMuc["nhommuc"].ToString();
								decimal d_Daukymucno=0,d_Daukymucco=0;
								if (s_mtm!="" && (i_Somuc==0 || (s_Duyetmuc.IndexOf(s_mtm+",")<0)))
								{
									System.Data.DataRow drSodu = dsSort.Tables[0].NewRow();
									drSodu["thangg"]=j.ToString().PadLeft(2,'0')+"/"+yy.ToString().PadLeft(4,'0');
									drSodu["nhommuc"]=s_mtm;
									drSodu["ngaygs"]=DateTime.Parse(j.ToString().PadLeft(2,'0')+"/01/"+yy.ToString());
									drSodu["soctg"]="";
									drSodu["ngayg"]=DateTime.Parse(j.ToString().PadLeft(2,'0')+"/01/"+yy.ToString());
									drSodu["diengiai"]="Số dư đầu tháng theo mục";
									drSodu["tkdoiung"]="";

									//Tham so cuoi: 1-lay so du no hoac phat sinh no, 2-lay so du co hoac phat sinh co.
									drSodu["sotienno"]=0;
									drSodu["sotienco"]=0;

									drSodu["tondauno"]=0;
									drSodu["tondauco"]=0;
					
									drSodu["fsnoquy"]=0;
									drSodu["fscoquy"]=0;

									drSodu["fsnonam"]=0;
									drSodu["fsconam"]=0;
						
									drSodu["ghichu"]="";
									drSodu["loaictu"]=3;
									drSodu["sapxep"]=int.Parse(yy.ToString()+j.ToString().PadLeft(2,'0')+"3");


									if (j==mm1)
									{
										d_Daukymucno=a.get_Sodudauky_muc(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,s_mtm,1);
										d_Daukymucco=a.get_Sodudauky_muc(j.ToString().PadLeft(2,'0'),s_yy,s_IDtk,s_IDlk,s_mtm,2);
									}
									else
									{
										s_mmyyyy=(j-1).ToString().PadLeft(2,'0')+"/"+numNam.Value.ToString().PadLeft(4,'0');
										decimal d_Luyke_ds_no=a.get_Sumfield_ds(dsData,"thangg",s_mmyyyy,"nhommuc",s_mtm,"sotienno","sotienco",1);
										decimal d_Luyke_ds_co=a.get_Sumfield_ds(dsData,"thangg",s_mmyyyy,"nhommuc",s_mtm,"sotienno","sotienco",2);

										d_Daukymucno=(d_Daukymucno+d_Luyke_ds_no) - Math.Min((d_Daukymucno+d_Luyke_ds_no),(d_Daukymucco+d_Luyke_ds_co));
										d_Daukymucco=(d_Daukymucco+d_Luyke_ds_co) - Math.Min((d_Daukymucno+d_Luyke_ds_no),(d_Daukymucco+d_Luyke_ds_co));
									}

									drSodu["tondaumucno"]=d_Daukymucno;
									drSodu["tondaumucco"]=d_Daukymucco;
									dsSort.Tables[0].Rows.Add(drSodu);
									dsSort.AcceptChanges();
								
									i_Somuc++;
									s_Duyetmuc+=s_mtm+",";
								}
							}
							catch{}	;
						}
					}
				}
			}
			catch{};
			try
			{
				dsData=dsSort.Copy();
				if (flag_dsnull && sumAll==0) MessageBox.Show("Không có số liệu !","Thông báo !");
				else
				{

					//dsData.WriteXml("..\\..\\xml_data\\KT_Socai_ct_muc.xml",XmlWriteMode.WriteSchema);
					s_Report="KT_Socai_ct_muc.rpt";
					string title_Ngaythang=""; 
					if (mm1==mm2) title_Ngaythang="Tháng "+mm1+" năm "+yy;
					else title_Ngaythang="Từ tháng "+mm1+" đến tháng "+mm2+" năm "+yy;

					string title_Taikhoan="Tài khoản : "+txtSotaikhoan.Text+" - "+txtTentaikhoan.Text;
					string title_Nguon="",title_Loai="",title_Khoan="";
					string title_Denthang=numDenthang.Value.ToString();
					if (s_Nguonns!="") title_Nguon=s_Nguonns;
					if (txtLoaikhoan.Text!="") 
					{
						title_Loai=txtLoaikhoan.Text.Trim().Split('-')[0].ToString();
						title_Khoan=txtLoaikhoan.Text.Trim().Split('-')[1].ToString();
					}
					
					if (loai==1)
					{
						//dsData.WriteXml("..\\xml\\KT_SoCai_theomuc.xml",XmlWriteMode.WriteSchema);
						frmReport f=new frmReport(a,dsData,title_Ngaythang,title_Taikhoan,title_Nguon,title_Loai,title_Khoan,title_Denthang,s_Report.ToString());
						f.ShowDialog();
					}
					else Print.Printer(a,dsData,title_Ngaythang,title_Taikhoan,title_Nguon,title_Loai,title_Khoan,title_Denthang,s_Report.ToString(),1,1);
				}
			}
			catch
			{
				MessageBox.Show("Không có số liệu !","Thông báo !");
			}
		}

		private void butXem_Click(object sender, System.EventArgs e)
		{
			Display(1);
		}

		private void butIn_Click(object sender, System.EventArgs e)
		{
			Display(2);
		}
	}
}
